/**
 * A simple banner applet.
 * This applet create a thread that scrolls the message 
 * contained in msg right to left across the applet window.
 */
package isa.mayouzhong.javastudy.applet;

/**
 * @author mayouzhong
 *
 */
import java.awt.*;
import java.applet.*;
/*
 * <applet code="SimpleBanner" width=300 height=50>
 * </applet>
 * */
public class SimpleBanner extends Applet implements Runnable{

	/**
	 * @param args
	 */
	String msg = "A simple moving string!";
	Thread t = null;
	int state;
	boolean stopFlag;
	
	public void init()
	{
		setBackground(Color.cyan);
		setForeground(Color.red);
	}
	//start the thread
	public void start()
	{
		t = new Thread(this);
		stopFlag = false;
		t.start();
	}
	
	//Entry point for the thread that runs the banner
	
	public void run()
	{
		char ch;
		//Display the banner
		for(;;)
		{
			try
			{
				repaint();
				Thread.sleep(250);
				ch = msg.charAt(0);
				msg = msg.substring(1,msg.length());
				msg += ch;
				if(stopFlag)
					break;
				
			}catch(InterruptedException e){}
		}
	}
	
	public void stop()
	{
		stopFlag = true;
		t = null;
	}
	//Display the banner
	public void paint(Graphics g)
	{
		g.drawString(msg, 50, 30);
	}

}
